/**
 * 
 */
package info.niwota.profile;

import java.util.Date;
import java.util.List;
import java.util.Locale;

import android.content.Context;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.net.Uri;

/**
 * @author qiangli
 * 
 */
public class Profiles {

	/**
	 * 
	 */
	private Profiles() {
	}

	public static Intent createCallIntent(String number) {
		// new Intent(Intent.ACTION_VIEW, Uri.parse("tel:"+ number));
		// Intent.ACTION_CALL_PRIVILEGED
		Intent i = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel", number,
				null));
		return i;
	}

	public static Intent createTextIntent(String number) {
		Intent i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("sms",
				number, null));
		return i;
	}

	public static Intent createEmailIntent(String[] emails) {
		Intent i = new Intent();
		i.setAction(Intent.ACTION_SEND);
		i.setType("message/rfc822");
		// email
		i.putExtra(Intent.EXTRA_EMAIL, emails);
		// i.putExtra(Intent.EXTRA_SUBJECT, "");
		// i.putExtra(Intent.EXTRA_TEXT, "");
		//
		return i;
	}

	public static Intent createMapIntent(Context ctx, String addr) throws Exception {
		try {
			Intent i = new Intent();
			i.setAction(Intent.ACTION_VIEW);
			Geocoder geoCoder = new Geocoder(ctx, Locale.getDefault());
			List<Address> addresses = geoCoder.getFromLocationName(addr, 1);
			if (addresses.size() > 0) {
				Address a0 = addresses.get(0);
				int latitude = (int) (a0.getLatitude() * 1E6);
				int longitude = (int) (a0.getLongitude() * 1E6);
				String geoUrl = "geo:" + latitude + "," + longitude + "?z=1";
				i.setData(Uri.parse(geoUrl));
				return i;
			}
		} catch (Exception e) {
			throw e;
		}
		return null;
	}

	public static Object formatModified(long date) {
		return new Date(date).toLocaleString();
	}
}
